package org.black.missedCall2.reply.broadcastReceiver.sms;

import org.black.missedCall2.MissedCallConstant;
import org.black.missedCall2.reply.ReplyConstant;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;

public class SentSMSBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		int resultCode = getResultCode();
		Log.d(ReplyConstant.REPLY_TAG, "result code : " + resultCode);

		switch (resultCode) {
		case Activity.RESULT_OK:
			Log.d(MissedCallConstant.APP_TAG, "Send Success.");
			ContentValues values = new ContentValues();
			Bundle bundle = intent.getExtras();
			values.put("date", System.currentTimeMillis());
			values.put("read", 0);
			values.put("type", 2);
			values.put("address",
					bundle.getString(ReplyConstant.INTENT_DESTINATION_ADDRESS));
			values.put("body", bundle.getString(ReplyConstant.INTENT_TEXT));
			context.getContentResolver().insert(
					Uri.parse("content://sms/sent"), values);
			Log.d(ReplyConstant.REPLY_TAG, "Insert SMS.");
			break;
		case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
			Log.d(ReplyConstant.REPLY_TAG, "Generic Fail!");
			break;
		case SmsManager.RESULT_ERROR_NO_SERVICE:
			Log.d(ReplyConstant.REPLY_TAG, "No SMS Service");
			break;
		case SmsManager.RESULT_ERROR_NULL_PDU:
			Log.d(ReplyConstant.REPLY_TAG, "PDU Error!");
			break;
		case SmsManager.RESULT_ERROR_RADIO_OFF:
			Log.d(ReplyConstant.REPLY_TAG, "Radio Off!");
			break;
		}

	}

}
